<?php
/**
*
* @package ppkBB3cker
* @version $Id: posting_add1.php 1.000 2009-05-14 15:49:00 PPK $
* @copyright (c) 2009 PPK
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

$ppkbb_torrblock_width=my_split_config($config['ppkbb_torrblock_width'], 13, 'my_int_val');
$ppkbb_torr_blocks=my_split_config($config['ppkbb_torr_blocks'], 9, 'my_int_val');

if(@$torrents_attach['torrent'])
{
	foreach ($torrents_attach['torrent'] as $torrent_data)
	{
		$torrent_link=1;
		$torrent_data['filesize'] = get_formatted_filesize($torrent_data['filesize']);
		$torrent_basename=utf8_basename(urldecode($torrent_data['real_filename']));
		$torrent_src_link=append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'id=' . (int) $torrent_data['attach_id'], true, ($torrent_data['is_orphan']) ? $user->session_id : false);
		$torrent_link ? $torrent_link=$torrent_src_link : $torrent_link='';
		$magnet_src_img=$phpbb_root_path.'images/tracker/filesaveas_big.png';
		$magnet_link=$magnet_src_link='';
		$torrent_shortname=$ppkbb_torrblock_width[2] && utf8_strlen($torrent_basename)>$ppkbb_torrblock_width[2] ? utf8_substr($torrent_basename, 0, $ppkbb_torrblock_width[2]).'...' : $torrent_basename;
		$magnet_src_img=$phpbb_root_path.'images/tracker/filesaveas_big.png';
		/*$torrent_data['size_lang'] = ($torrent_data['filesize'] >= 1048576) ? $user->lang['MIB'] : (($torrent_data['filesize'] >= 1024) ? $user->lang['KIB'] : $user->lang['BYTES']);
		$torrent_data['filesize'] = get_formatted_filesize($torrent_data['filesize']);
		$torrent_basename=utf8_basename($torrent_data['real_filename']);*/
		$template->assign_block_vars('torrent_fields', array(
			'TORRENT_DOWNLOAD_TXT' => sprintf(($torrent_link ? '<a href="'.$torrent_link.'" title="%1$s">'.$user->lang['DOWNLOAD_TORRENT'].'</a>' : '%1$s'), $torrent_basename),
			'TORRENT_DOWNLOAD_IMG' => sprintf(($torrent_link ? '<a href="'.$torrent_link.'" title="'.$user->lang['DOWNLOAD_TORRENT'].'">%1$s</a>' : '%1$s'), '<img alt="" src="' . $phpbb_root_path . 'images/tracker/filesave_big.png" alt="' . $user->lang['DOWNLOAD_TORRENT'] . '" />', $torrent_basename),

			//'TORRENT_DOWNLOAD_SRC_IMG' => $phpbb_root_path . 'images/tracker/filesave_big.png',
			//'TORRENT_FILENAME' => $torrent_filename,
			//'TORRENT_SRC_LINK' => $torrent_link ? $torrent_src_link : '',

			//'TORRENT_MAGNET_LINK' => $magnet_link ? $magnet_src_link : '',
			'TORRENT_MAGNET_TXT'	=> $magnet_link ? $magnet_link : '',
			//'TORRENT_MAGNET_SRC_IMG'	=> $magnet_src_img,
			//'TORRENT_MAGNET_WINDOW' => $magnet_link ? ($ppkbb_torrent_magnetlink[0]==1 ? true : false) : '',

			'TORRENT_FILESIZE' => $torrent_data['filesize'],
			'TORRENT_ALTITLE' => $torrent_basename,
			'TORRENT_COMMENT' => $torrent_data['attach_comment'] ? '[<a class="my_tt" title="'.$torrent_data['attach_comment'].'">?</a>]' : '',
			'TORRENT_COMMENT_TEXT' => $torrent_data['attach_comment'] ? $torrent_data['attach_comment'] : '',
			'TORRENT_DOWNLOADED' => $torrent_data['download_count'],
			/*'TORRENT_LINK' => append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . (int) $torrent_data['attach_id'], true, ($torrent_data['is_orphan']) ? $user->session_id : false),
			'TORRENT_SRC' => $phpbb_root_path . 'images/tracker/filesave_big.png',
			'TORRENT_FILESIZE'			=> $torrent_data['filesize'],
			'TORRENT_DOWNLOAD_NAME'		=> utf8_strlen($torrent_basename)>$ppkbb_torrblock_width[2] ? utf8_substr($torrent_basename, 0, $ppkbb_torrblock_width[2]).'...' : $torrent_basename,
			'TORRENT_COMMENT'			=> @$torrent_data['comment'],
			'TORRENT_DOWNLOADED'			=>$torrent_data['download_count']*/
			)
		);
	}
}

if(@$torrents_attach['poster'])
{
	$poster_addon='';
	foreach($torrents_attach['poster'] as $poster_data)
	{
		if(!$poster_data['i_external'])
		{
			if($poster_data['thumbnail'] && $ppkbb_torr_blocks[2]==1)
			{
				$poster_addon='&amp;t=1';
			}
			$poster_data['filesize'] = get_formatted_filesize($poster_data['filesize']);
			$poster_basename=utf8_basename($poster_data['real_filename']);
			$poster_wh=tracker_get_thumb_size($poster_data['i_width'], $poster_data['i_height'], $ppkbb_torrblock_width[8], $ppkbb_torrblock_width[9], ($ppkbb_torrblock_width[12] ? true : false));

			/*$poster_data['size_lang'] = ($poster_data['filesize'] >= 1048576) ? $user->lang['MIB'] : (($poster_data['filesize'] >= 1024) ? $user->lang['KIB'] : $user->lang['BYTES']);
			if($poster_data['filesize'] > $config['ppkbb_tmin_thumbsize'])
			{
				//$poster_addon='&amp;t=1';
			}
			$poster_data['filesize'] = get_formatted_filesize($poster_data['filesize']);
			$poster_wh=tracker_get_img_size_format($poster_data['i_width'], $poster_data['i_height']);*/
			$template->assign_block_vars('torrent_poster_fields', array(
				'POSTER_LINK' => append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'mode=view&amp;id=' . (int) $poster_data['attach_id'], true, ($poster_data['is_orphan']) ? $user->session_id : false).'&amp;ext=.'.$poster_data['extension'],
				'POSTER_SRC' => append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'id=' . $poster_data['attach_id'] . $poster_addon),
				'POSTER_FILESIZE'	=> $poster_data['filesize'],
				'POSTER_WH_WIDTH' => $poster_wh[0] ? $poster_wh[0] : false,
				'POSTER_WH_HEIGHT' => $poster_wh[1] ? $poster_wh[1] : false,
				'POSTER_DOWNLOAD_NAME'		=> $ppkbb_torrblock_width[2] && utf8_strlen($poster_basename)>$ppkbb_torrblock_width[2] ? utf8_substr($poster_basename, 0, $ppkbb_torrblock_width[2]).'...' : $poster_basename,
				'POSTER_ALTITLE'			=> $poster_basename,
				'POSTER_COMMENT'			=> @$poster_data['attach_comment'] ? '[<a href="#" title="'.$poster_data['attach_comment'].'" alt="'.$poster_data['attach_comment'].'">?</a>]' : '',
				'POSTER_CLCOMMENT'			=> @$poster_data['attach_comment'],
				'POSTER_DOWNLOADED'			=>$poster_data['download_count'],
				'POSTER_FORUM'=>1,
				/*'POSTER_LINK'=>append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&amp;id=' . (int) $poster_data['attach_id'], true, ($poster_data['is_orphan']) ? $user->session_id : false),
				'POSTER_SRC' =>append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $poster_data['attach_id'] . $poster_addon),
				'POSTER_FILESIZE'	=>$poster_data['filesize'],
				'POSTER_WH'=>$poster_wh[0] && $poster_data['i_width'] > $poster_wh[0] ? ' width="'.$poster_wh[0].'" height="'.$poster_wh[1].'"' : '',
				'POSTER_DOWNLOAD_NAME'=>utf8_basename($poster_data['real_filename']),
				'POSTER_COMMENT'			=>@$poster_data['comment'],
				'POSTER_DOWNLOADED'			=>$poster_data['download_count']*/
				)
			);
		}
		else
		{
			$poster_wh=tracker_get_thumb_size($poster_data['i_width'], $poster_data['i_height'], $ppkbb_torrblock_width[8], $ppkbb_torrblock_width[9], ($ppkbb_torrblock_width[12] ? true : false));
			$template->assign_block_vars('torrent_poster_fields', array(
				'POSTER_LINK' => $poster_data['real_filename'],
				'POSTER_SRC' => $poster_data['real_filename'],
				'POSTER_WH_WIDTH' => $poster_wh[0] ? $poster_wh[0] : false,
				'POSTER_WH_HEIGHT' => $poster_wh[1] ? $poster_wh[1] : false,
				'POSTER_FORUM' => 0,
				)
			);
		}
	}
}

if(@$torrents_attach['screenshot'])
{
	$screenshot_addon='';
	foreach ($torrents_attach['screenshot'] as $screenshot_data)
	{
		if(!$screenshot_data['i_external'])
		{
			if($screenshot_data['thumbnail'] && $ppkbb_torr_blocks[3]==1)
			{
				$screenshot_addon='&amp;t=1';
			}
			$screenshot_data['filesize'] = get_formatted_filesize($screenshot_data['filesize']);
			$screenshot_basename=utf8_basename($screenshot_data['real_filename']);
			$screenshot_wh=tracker_get_thumb_size($screenshot_data['i_width'], $screenshot_data['i_height'], $ppkbb_torrblock_width[10], $ppkbb_torrblock_width[11], ($ppkbb_torrblock_width[12] ? true : false));
			/*$screenshot_data['size_lang'] = ($screenshot_data['filesize'] >= 1048576) ? $user->lang['MIB'] : (($screenshot_data['filesize'] >= 1024) ? $user->lang['KIB'] : $user->lang['BYTES']);
			if($screenshot_data['filesize'] > $config['ppkbb_tmin_thumbsize'])
			{
				//$screenshot_addon='&amp;t=1';
			}
			$screenshot_data['filesize'] = get_formatted_filesize($screenshot_data['filesize']);
			$screenshot_wh=tracker_get_img_size_format($screenshot_data['i_width'], $screenshot_data['i_height']);*/
			$template->assign_block_vars('torrent_screenshot_fields', array(
				'SCREENSHOT_LINK' => append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'mode=view&amp;id=' . (int) $screenshot_data['attach_id'], true, ($screenshot_data['is_orphan']) ? $user->session_id : false).'&amp;ext=.'.$screenshot_data['extension'],
				'SCREENSHOT_SRC' => append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'id=' . $screenshot_data['attach_id'] . $screenshot_addon),
				'SCREENSHOT_FILESIZE'			=> $screenshot_data['filesize'],
				'SCREENSHOT_WH_WIDTH' => $screenshot_wh[0] ? $screenshot_wh[0] : false,
				'SCREENSHOT_WH_HEIGHT' => $screenshot_wh[1] ? $screenshot_wh[1] : false,
				'SCREENSHOT_DOWNLOAD_NAME'		=> $ppkbb_torrblock_width[2] && utf8_strlen($screenshot_basename)>$ppkbb_torrblock_width[2] ? utf8_substr($screenshot_basename, 0, $ppkbb_torrblock_width[2]).'...' : $screenshot_basename,
				'SCREENSHOT_ALTITLE'			=> $screenshot_basename,
				'SCREENSHOT_COMMENT'			=> @$screenshot_data['attach_comment'] ? '[<a href="#" title="'.$screenshot_data['attach_comment'].'" alt="'.$screenshot_data['attach_comment'].'">?</a>]' : '',
				'SCREENSHOT_CLCOMMENT'			=> @$screenshot_data['attach_comment'],
				'SCREENSHOT_DOWNLOADED'			=>$screenshot_data['download_count'],
				'SCREENSHOT_FORUM'=>1,
				/*'SCREENSHOT_LINK' => append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&amp;id=' . (int) $screenshot_data['attach_id'], true, ($screenshot_data['is_orphan']) ? $user->session_id : false),
				'SCREENSHOT_SRC' => append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $screenshot_data['attach_id'] . $screenshot_addon),
				'SCREENSHOT_FILESIZE'			=> $screenshot_data['filesize'],
				'SCREENSHOT_WH'=>$screenshot_wh[0] && $screenshot_data['i_width'] > $screenshot_wh[0] ? ' width="'.$screenshot_wh[0].'" height="'.$screenshot_wh[1].'"' : '',
				'SCREENSHOT_DOWNLOAD_NAME'		=> utf8_basename($screenshot_data['real_filename']),
				'SCREENSHOT_COMMENT'			=> @$screenshot_data['comment'],
				'SCREENSHOT_DOWNLOADED'			=>$screenshot_data['download_count']*/
				)
			);
		}
		else
		{
			$screenshot_wh=tracker_get_thumb_size($screenshot_data['i_width'], $screenshot_data['i_height'], $ppkbb_torrblock_width[10], $ppkbb_torrblock_width[11], ($ppkbb_torrblock_width[12] ? true : false));
			$template->assign_block_vars('torrent_screenshot_fields', array(
				'SCREENSHOT_LINK' => $screenshot_data['real_filename'],
				'SCREENSHOT_SRC' => $screenshot_data['real_filename'],
				'SCREENSHOT_WH_WIDTH' => $screenshot_wh[0] ? $screenshot_wh[0] : false,
				'SCREENSHOT_WH_HEIGHT' => $screenshot_wh[1] ? $screenshot_wh[1] : false,
				'SCREENSHOT_FORUM' => 0,
				)
			);
		}
	}
}
?>
